home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
CC_C
/
0151.ZIP
/
TWIDANSI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-08-03
|
3KB
|
145 lines
#define RIGHT 79 /* number of columns (0 - N) */
#define TOP 24 /* number of lines (0 - N) */
#define CAR_LENGTH 24
#define OBSTACLE 60
#define WHERE 49
#define RATIO (RIGHT/TOP)
#define BOX_TOP 3
/* Note 20 Jun 85 ... no excuses for the code. Hack the following
functions to fit your terminal. Tom Jennings */
/* Place the cursor at X and Y */
place(x,y)
int x,y;
{
printf("\033[%d;%df",TOP - x + 1, y + 1);
}
/* Clear the screen */
clear() {
printf("\033[2J");
}
/* Waste some time */
sleep(n)
int n;
{
long x;
while (n--) for (x= 0L; x < 2000L; x++);
}
/* Plot a character at a location */
plot(x,y,c)
int x,y;
char c;
{
place(x,y);
printf("%c",c);
}
/* and another twiddle. Crash a car into the CRT edges. never stops,
no exit. tj 2/18/81 */
main (argc,argv)
int argc;
char **argv;
{
int i;
do {
/* Erase the screen, draw the road and some things to crash into. */
clear();
plot_sky();
place(0,0);
for (i= 0; i < RIGHT; i++) printf("=");
for (i= 1; i < BOX_TOP; i++) {
plot(i,0,'|');
plot(i,OBSTACLE,'|'); /* draw the sides of */
plot(i,OBSTACLE + 10,'|'); /* the obstacle */
}
for (i= OBSTACLE + 1; i < OBSTACLE + 10; i++)
plot(BOX_TOP,i,'-'); /* plot the top */
for (i= 1; i < (OBSTACLE - CAR_LENGTH); i++) {
plot_car(i);
}
plot_eh();
place(7,WHERE); printf(" Ouch!");
place(6,WHERE); printf("/ ");
sleep(8);
place(7,WHERE); printf(" ");
place(6,WHERE); printf(" ");
/* Now fling the guy out the windshield */
for (i= 0; i < RIGHT - WHERE - 4; i++) {
plot_guy(i);
}
plot_frown();
place(i / RATIO, 70); printf("splat!");
sleep(10);
} while (argc < 2);
}
/* Plot the car at a location. Dont forget to erase the old one. Try
changing every \\ to \ to see what the car really looks like. */
plot_car(i)
int i;
{
place(5,i); printf(" /------\\ ");
place(4,i); printf(" ,_____/......|.\\____ ");
place(3,i); printf(" O __ | __O ");
place(2,i); printf(" |__/ \\________|_/ \\ ");
place(1,i); printf(" \\ / \\ / ");
}
/* Plot the guy flung out the window. */
plot_guy(i)
int i;
{
place((i / RATIO) + 7,i + WHERE); printf(" 0 ");
place((i / RATIO) + 6,i + WHERE); printf(" /-- ");
place((i / RATIO) + 5,i + WHERE); printf(" /| ");
place((i / RATIO) + 4,i + WHERE); printf(" ");
}
/* Plot the sky */
plot_sky() {
place(22,50); printf(" \\ | / ");
place(21,50); printf(" _ _ ");
place(20,50); printf(" -- -- ");
place(19,50); printf(" \\___/ ");
place(18,50); printf(" -- -- ");
place(17,50); printf(" / | \\ ");
}
/* Plot that the sun noticed what happened */
plot_eh() {
place(21,40); printf("oops!");
place(20,40); printf(" \\");
place(19,50); printf(" --- ");
}
/* Plot the suns frown. Displeasure at the splat. */
plot_frown() {
place(21,40); printf("Yecch!");
place(21,50); printf(" \\ / ");
place(19,50); printf(" /---\\ ");
}